<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>商品统计</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        .layui-table-cell {
            height: auto;
            white-space: normal;
        }

        .layui-table img {
            max-width: 300px;
        }
    </style>
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <fieldset class="table-search-fieldset">
                <div style="margin: 10px 10px 10px 10px">
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">商品名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="goodsName" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">商品类别</label>
                                <div class="layui-input-inline">
                                    <select name="goodsCategory" id="goodsCategory" class="layui-input">
                                        <option value="">全部</option>
                                        <option value="3C">3C数码</option>
                                        <option value="study">文具类</option>
                                        <option value="book">书籍</option>
                                        <option value="normal">日用品</option>
                                        <option value="food">食品</option>
                                    </select>
                                </div>

                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>

            <script type="text/html" id="imgShow">
                <img src="{{d.goodsImg}}" style="width: 200px;"/>
            </script>

            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

            <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="view">查看</a>
        </script>

        </div>
    </div>
    <script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;

            table.render({
                elem: '#currentTableId',
                url: '../api/goods.json',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [[
                    { field: 'id', width: 120, title: 'ID', sort: true },
                    { field: 'goodsImg', title: '商品图片', align: "center", templet: "#imgShow" },
                    { field: 'goodsName', minWidth: 80, title: '商品名' },
                    { field: 'goodsCategory', width: 120, title: '类别', sort: true, align: "center" },
                    { field: 'saleCount', width: 120, title: '销售数量', sort: true, align: "right" },
                    { field: 'saleSum', minWidth: 80, title: '销售额', sort: true, align: "right" },
                    { title: '操作', toolbar: '#currentTableBar', align: "center" }
                ]],
                limits: [10, 20, 100],
                limit: 10,
                page: true,
                skin: 'line',
                height: 'full-148'
            });

            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                var result = JSON.stringify(data.field);
                layer.alert(result, {
                    title: '最终的搜索信息'
                });

                //执行搜索重载
                table.reload('currentTableId', {
                    page: {
                        curr: 1
                    }
                    , where: {
                        searchParams: result
                    }
                }, 'data');

                return false;
            });

            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                if (obj.event === 'view') {
                    var index = layer.open({
                    title: '查看商品',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['60%', '90%'],
                    content: '../page/table/good-view.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
                } else if (obj.event === 'delete') {

                }
            });

           
        });

    </script>

</body>

</html>